package 算法练习;
/**
 * @author： li
 * @date： 2022-01-07 15:05
 * @version 1.0
 */

import java.util.Scanner;
public class 跳马01 {
    private static int t=0;//跳的第几次 每次有8种跳法
    private static int o=0;
    private static int[] save_x =new int[10];
    private static int[] save_y = new int[10];
    private static int[][] isOk = new int[8][8];
    private static int[][] p = new int[8][8];
    private static int a,b,c,d;
    private static int[] fx= { 2, 1,-1,-2,-2,-1, 1, 2};
    private static int[] fy= {-1,-2,-2,-1, 1, 2, 2, 1};
    public boolean check(int x,int y)
    {
        if(x<0 || y<0 || x> 8 || y>8){
            return false;
        }
        return true;
    }
    public void horseRun(int x,int y,int step) {
        for (int i = 0; i < 8; i++) { //表示每一个格都有八种走法
            if (check((x+fx[i]), (y+fy[i]))) {
                step++;
//                System.out.print("开始跳马");
                int xx = x + fx[i];
                int yy = y + fy[i];
                isOk[xx][yy] = p[xx][yy];
                save_x[i] = xx;
                save_y[i] = yy;
                }
            }
        checkResult();
//        for (int i = 0; i < 8; i++) {
//        if(p[c][d]==isOk[save_x[i]][save_y[i]]){
//            System.out.println(step);
//            return;
//        }else {
//            horseRun(save_x[i],save_y[i],0);
//            initIsok();
//            init(save_x);
//            init(save_y);
//        }
//        }
        //checkResult(step);
//        System.out.println("步"+step);
    }
    public void checkResult(){
        t++;
        for (int i = 0; i < 8; i++) {
            if(p[c][d]==isOk[save_x[i]][save_y[i]]){
                System.out.println(t);
                return;
            }
        }
//        initIsok();
        horseRun(save_x[o],save_y[o],0);
        o++;
    }
    public static void initIsok(){
        for(int i=0;i<8;i++)
            for(int j=0;j<8;j++){
                isOk[i][j]=1;
            }
    }
    public static void init(int[] a){
        for(int i=0;i<8;i++)
                a[i]=1;
    }
    public static void main(String[] args) {
        int k=1;int step=0;
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();b = sc.nextInt();
        c = sc.nextInt();d = sc.nextInt();
        for(int i=0;i<8;i++)
            for(int j=0;j<8;j++){
                p[i][j] = k;
                k++;
            }
        for(int i=0;i<8;i++)
            for(int j=0;j<8;j++){
                isOk[i][j]=1;
            }
        for(int i=0;i<8;i++)
            for(int j=0;j<8;j++){
                System.out.print(p[i][j]+"  ");
                if (j==7) System.out.println(" ");
            }
        跳马01 ep = new 跳马01();
        if(a==c&&b==d){
            System.out.println(0);
        }else {
            ep.horseRun(a,b,step);
            for(int i=0;i<8;i++)
                for(int j=0;j<8;j++){
                    System.out.print(isOk[i][j]+"  ");
                    if(j==7) System.out.println(" ");
                }
            for(int i=0;i<10;i++) System.out.print(+save_x[i]+" ");
            System.out.println(" ");
            for(int i=0;i<10;i++)  System.out.print(save_y[i]+" ");
        }
    }
}
